/*
 * Copyright (C) 2015 Daniel Uppenkamp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.maurersmarbles.drawables;

import com.google.common.base.Preconditions;
import com.googlecode.maurersmarbles.Rectangle;
import com.googlecode.maurersmarbles.ScreenCanvas;

/**
 *
 * @author Daniel Uppenkamp
 */
public class RectangleDrawable implements Drawable {

    /**
     * Whether or not the rectangle is filled.
     */
    protected boolean filled;
    /**
     * The color of the rectangle.
     */
    protected int rgb;
    /**
     * The rectangle.
     */
    protected Rectangle rectangle;

    /**
     * Creates a new RectangleDrawable.
     *
     * @param rectangle the rectangle
     * @param rgb the color
     */
    public RectangleDrawable(Rectangle rectangle, int rgb) {
        this(rectangle, rgb, false);
    }

    /**
     * Creates a new RectangleDrawable.
     *
     * @param rectangle the rectangle
     * @param rgb the color
     * @param filled whether or not the rectangle is filled
     */
    public RectangleDrawable(Rectangle rectangle, int rgb, boolean filled) {

        Preconditions.checkNotNull(rectangle);

        this.rectangle = rectangle;
        this.rgb = rgb;
        this.filled = filled;

    }

    /**
     * Creates a new RectangleDrawable.
     *
     * @param x the upper left x coordinate of the rectangle
     * @param y the upper left y coordinate of the rectangle
     * @param width the width of the rectangle
     * @param height the height of the rectangle
     * @param rgb the color
     */
    public RectangleDrawable(int x, int y, int width, int height, int rgb) {
        this(x, y, width, height, rgb, false);
    }

    /**
     * Creates a new RectangleDrawable.
     *
     * @param x the upper left x coordinate of the rectangle
     * @param y the upper left y coordinate of the rectangle
     * @param width the width of the rectangle
     * @param height the height of the rectangle
     * @param rgb the color
     * @param filled whether or not the rectangle is filled
     */
    public RectangleDrawable(int x, int y, int width, int height, int rgb, boolean filled) {
        this(new Rectangle(x, y, width, height), rgb, filled);
    }

    @Override
    public void draw(ScreenCanvas screenCanvas) {
        if (filled) {
            screenCanvas.fillRect(rectangle, rgb);
        }
        else {
            screenCanvas.drawRect(rectangle, rgb);
        }
    }

}
